package com.webserver.core;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/*
 线程任务
 负责与特定的客服端进行HTTP交互
 */
public class ClientHandler implements Runnable{//实现了接口要重写他的方法
    //提升作用域
    private Socket socket;

    //构造方法，初始化
    public ClientHandler(Socket socket){
        this.socket = socket;
    }

    @Override
    public void run() {
        //http://localhost:8088/
        try {
            //1解析请求
            InputStream in = socket.getInputStream();
            int d;
            while ((d=in.read()) != -1){
                System.out.println((char) d);
            }

            //2处理请求
            //3发送响应

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                //响应候断开连接
                socket.close();
            } catch (IOException e) {
                System.out.println("关闭流异常！");
            }
        }

    }
}
